package TeamR3.dao.impl;

import java.util.List;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import TeamR3.dao.CustomerDao;
import TeamR3.entity.Customer;

@Repository("customerDao")
public class CustomerDaoImpl implements CustomerDao {
	@Autowired
	SqlSessionTemplate sqlSessionTemplate = null;

	public void setSqlSessionTemplate(SqlSessionTemplate sqlSessionTemplate) {
		this.sqlSessionTemplate = sqlSessionTemplate;
	}

	@Override
	public List<Customer> queryCustomerInfo(long identity, String customer_name) {
		Customer tempCustomer = new Customer();
		tempCustomer.setIdentity(identity);
		tempCustomer.setCustomer_name(customer_name);
		return sqlSessionTemplate.selectList("queryCustomerInfo", tempCustomer);
	}

	@Override
	public int addCustomerInfo(long identity, String customer_name,
			String customer_tel, int customer_point) {
		return sqlSessionTemplate.insert("addCustomerInfo", new Customer(
				identity, customer_name, customer_tel, customer_point));
	}

	@Override
	public int modifyCustomerInfo(long identity, String customer_name,
			String customer_tel, int customer_point) {
		return sqlSessionTemplate.update("modifyCustomerInfo", new Customer(
				identity, customer_name, customer_tel, customer_point));
	}

	@Override
	public int delCustomerInfo(long identity) {
		return sqlSessionTemplate.delete("delCustomerInfo", identity);
	}

}
